using System.Collections;
using UnityEngine;

public class EOTDREWRITE_FountainRoom : MonoBehaviour
{
	public int CutsceneIndex;

	[Header("-- Cutscene References --")]
	[SerializeField]
	private CameraManager PlayerCamera;

	[Header("Characters")]
	[SerializeField]
	private PlayerManager Kris;

	[SerializeField]
	private Susie_Follower Susie;

	[SerializeField]
	private Susie_Follower Ralsei;

	[Header("Character Positions")]
	[SerializeField]
	private Transform SusieStartPos;

	[SerializeField]
	private Transform RalseiStartPos;

	[Header("UI")]
	[SerializeField]
	private GameObject CutsceneFade;

	[Header("-- Cutscene Settings --")]
	[SerializeField]
	private AudioClip Music_Fountain;

	[SerializeField]
	private AudioClip Music_Friendship;

	[SerializeField]
	private CHATBOXTEXT[] CutsceneChats;

	private void Start()
	{
		Kris = PlayerManager.Instance;
		IncrementCutsceneIndex();
		((MonoBehaviour)this).StartCoroutine(Cutscene());
	}

	private void Update()
	{
		if (CutsceneIndex > 0)
		{
			Kris._PlayerState = PlayerManager.PlayerState.Cutscene;
			DarkworldMenu.Instance.CanOpenMenu = false;
		}
	}

	public void IncrementCutsceneIndex()
	{
		CutsceneIndex++;
	}

	private IEnumerator Cutscene()
	{
		yield return null;
		Susie = PartyMemberSystem.Instance.HasMemberInParty(PartyMemberSystem.Instance.Default_SusieDarkworld).PartyMemberFollowSettings;
		Ralsei = PartyMemberSystem.Instance.HasMemberInParty(PartyMemberSystem.Instance.Default_Ralsei).PartyMemberFollowSettings;
		((Component)Susie).transform.position = Vector2.op_Implicit(new Vector2(-8f, 0.092f));
		((Component)Ralsei).transform.position = Vector2.op_Implicit(new Vector2(-8f, -2.5f));
		if ((Object)(object)Susie == (Object)null)
		{
			MonoBehaviour.print((object)"Susie Missing?");
		}
		if ((Object)(object)Ralsei == (Object)null)
		{
			MonoBehaviour.print((object)"Ralsei Missing?");
		}
		if (PlayerPrefs.GetInt("EOTD_FinishedArgueCutscene", 0) == 0)
		{
			Susie.FollowingEnabled = false;
			Ralsei.FollowingEnabled = false;
			((Component)Susie).transform.position = SusieStartPos.position;
			((Component)Ralsei).transform.position = RalseiStartPos.position;
			Susie.RotateSusieToDirection(Vector2.right);
			Ralsei.RotateSusieToDirection(Vector2.down);
			PlayerManager.Instance._PMove.RotatePlayerAnim(Vector2.left);
			((Component)CameraManager.instance).transform.position = new Vector3(((Component)Ralsei).transform.position.x, ((Component)CameraManager.instance).transform.position.y, ((Component)CameraManager.instance).transform.position.z);
			CutsceneIndex = 1;
			PlayerPrefs.SetInt("EOTD_FinishedArgueCutscene", 1);
			MusicManager.PlaySong(Music_Fountain, FadePreviousSong: false, 0f);
			yield return (object)new WaitForSeconds(0.5f);
			yield return (object)new WaitForSeconds(0.5f);
			CutsceneUtils.RunFreshChat(CutsceneChats[0], 0, ForcePosition: true, OnBottom: true);
			DEBUG_EnableMarkiplier.ChangeMarkiplierState(DEBUG_EnableMarkiplier.MarkiplierEmotions.Shock);
			while (CutsceneIndex != 2)
			{
				yield return null;
			}
			SusieIdle_Up();
			KrisIdle_Up();
			yield return (object)new WaitForSeconds(1f);
			UI_FADE.Instance.StartFadeOut(0.35f);
			CutsceneFade.SetActive(false);
			DEBUG_EnableMarkiplier.ChangeMarkiplierState(DEBUG_EnableMarkiplier.MarkiplierEmotions.Horror);
			yield return (object)new WaitForSeconds(2f);
			CutsceneUtils.RunFreshChat(CutsceneChats[0], 1, ForcePosition: true, OnBottom: false);
			while (CutsceneIndex != 3)
			{
				yield return null;
			}
			DEBUG_EnableMarkiplier.ChangeMarkiplierState(DEBUG_EnableMarkiplier.MarkiplierEmotions.Crying);
			Vector3 val = default(Vector3);
			while (((Component)PlayerCamera).transform.position.x != ((Component)Kris).transform.position.x)
			{
				yield return null;
				((Vector3)(ref val))._002Ector(((Component)Kris).transform.position.x, ((Component)PlayerCamera).transform.position.y, ((Component)PlayerCamera).transform.position.z);
				((Component)PlayerCamera).transform.position = Vector3.MoveTowards(((Component)PlayerCamera).transform.position, val, 3f * Time.deltaTime);
			}
			PlayerCamera.FollowPlayerX = true;
			CutsceneIndex = 0;
			Kris.ResetToGameState();
			Susie.FollowingEnabled = true;
			Ralsei.FollowingEnabled = true;
			DarkworldMenu.Instance.CanOpenMenu = true;
			PlayerPrefs.SetInt("EOTD_FinishedArgueCutscene", 1);
		}
		else
		{
			CutsceneFade.SetActive(false);
			MusicManager.PlaySong(Music_Friendship, FadePreviousSong: false, 0f);
			CutsceneIndex = 0;
			PlayerCamera.FollowPlayerX = true;
			CutsceneIndex = 0;
			Kris.ResetToGameState();
			Susie.FollowingEnabled = true;
			Ralsei.FollowingEnabled = true;
			DarkworldMenu.Instance.CanOpenMenu = true;
			((Component)Kris).transform.position = Vector2.op_Implicit(new Vector2(-7.95f, -1.35f));
			((Component)Susie).transform.position = ((Component)Kris).transform.position;
			((Component)Ralsei).transform.position = ((Component)Kris).transform.position;
		}
	}

	public void SusieIdle_Right()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		Susie.SusieAnimator.Play("Idle");
		Susie.RotateSusieToDirection(Vector2.right);
	}

	public void SusieIdle_Up()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		Susie.SusieAnimator.Play("Idle");
		Susie.RotateSusieToDirection(Vector2.up);
	}

	public void SusieConfident_Right()
	{
		Susie.SusieAnimator.Play("SusieDarkworld_Proud_Right");
	}

	public void RalseiIdle_Down()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		Ralsei.SusieAnimator.Play("Idle");
		Ralsei.RotateSusieToDirection(Vector2.down);
	}

	public void RalseiIdle_Up()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		Ralsei.SusieAnimator.Play("Idle");
		Ralsei.RotateSusieToDirection(Vector2.up);
	}

	public void RalseiIdleBlush_Down()
	{
		Ralsei.SusieAnimator.Play("Ralsei_Blush_Down");
	}

	public void KrisIdle_Up()
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		Kris._PMove.RotatePlayerAnim(Vector2.up);
	}

	public void KrisIdle_Left()
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		Kris._PMove.RotatePlayerAnim(Vector2.left);
	}
}
